<template>
  <div>
    <div>
      <RHTable :RHTable="table" ref="r_h_table"></RHTable>
    </div>
    <!--弹出框-->
    <div>
      <RHDialog :RHDialog="dialog" ref="dialog" :RHForm="form" :RHPre="pre"></RHDialog>
    </div>
  </div>
</template>

<script>
import RHTable from "@/common/RHTable/index.vue";
import RHDialog from "@/common/form/dialogForm.vue";
export default {
  name: "commonModule_index",
  components: {
    RHTable,
    RHDialog
  },
  data: function() {
    return {
      param: {},
      table: {
        url:
          this.$store.state.url.user +
          "/api/users/ren/hai/common/module/getList",
        method: "get",
        header: {
          show: true,
          btn: [{ value: "新增", click: this.show }]
        },
        columns: [
          { fieId: "logId", title: "ID" },
          { fieId: "createName", title: "创建人" },
          { fieId: "createdTime", title: "创建时间" },
          { fieId: "updatedName", title: "更新人" },
          { fieId: "updatedTime", title: "更新时间" },
          { fieId: "commonModuleName", title: "组件名称" },
          { fieId: "commonModuleExplain", title: "组件说明", hide: true },
          { fieId: "commonModuleType", title: "类型", hide: true }
        ],
        columnsBtn: [{ value: "详情", click: this.detail, size: "mini" }],
        // 分页
        paging: true,
        //展示隐藏列
        hideColumn: true
      },
      dialog: {
        visible: false,
        title: "添加",
        btn: [
          {
            value: "添加",
            type: "primary",
            click: this.submitForm
          }
        ]
      },
      form: [
        //隐藏
        { el: "hide", model: "id" },
        //自定义验证
        {
          el: "input",
          label: "编号",
          prop: [
            {
              validator: async (rule, value, callback) => {
                const id = this.$refs.dialog.getForm().getForm("id");
                let res = await service.checkCode({
                  code: value,
                  id: id
                });
                if (res.entity > 0) {
                  callback(new Error("编号不能重复！"));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            },
            { required: true, message: "请输入编号", trigger: "blur" }
          ],
          model: "commonModuleCode"
        },
        {
          el: "select",
          label: "类型",
          prop: { required: true },
          model: "type",
          multiple: false, //是否多选
          candidate: {
            label: "name",
            value: "id",
            url:
              this.$store.state.url.user + "/api/users/renHaiTest/getSelectList"
          }
        },
        {
          el: "input",
          label: "顺序号",
          prop: [
            {
              required: true,
              max: 999,
              min: 0,
              message: "请输入顺序号",
              type: "number"
            }
          ],
          model: "seq"
        },
        {
          el: "date",
          dataType: "datetimerange",
          label: "开始结束时间",
          prop: [{ required: true, message: "请选择开始时间" }],
          startModel: "startTime",
          endModule: "endTime"
        }
      ]
    };
  },
  methods: {
    show() {
      this.dialog.visible = true;
    }
  }
};
</script>

<style scoped></style>
